package com.desay.pangoo.itmt.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.Data;

/**
 * 基类
 *
 * @author uidq1163
 */
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties({"handler", "hibernateLazyInitializer"})
@Data
public abstract class BaseEntity {
    @Column(name = "version", columnDefinition = "bigint default '0' COMMENT '数据版本号，用于并发乐观锁'")
    @Version
    private Long version;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, insertable = true, updatable = false, columnDefinition = "datetime default CURRENT_TIMESTAMP COMMENT '创建时间'")
    private Date createTime;

    /**
     * 创建者
     */
    @Column(name = "creator", nullable = true, insertable = true, updatable = false, columnDefinition = "varchar(255) COMMENT '创建者'")
    @CreatedBy
    private String creator;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "modify_time", insertable = false, updatable = true, columnDefinition = "datetime default CURRENT_TIMESTAMP COMMENT '更新时间'")
    private Date modifyTime;

    /**
     * 最后更新者
     */
    @Column(name = "updator", columnDefinition = "varchar(255) COMMENT '更新者'")
    @LastModifiedBy
    private String updator;
}
